package hotLeetcode;

import java.util.ArrayList;
import java.util.List;

public class Test12 {

    List<String> res = new ArrayList<>();
    StringBuilder sb = new StringBuilder();

    public List<String> letterCombinations(String digits) {
        if (digits == null || digits.length() == 0) {
            return res;
        }
        String[] numStrings = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        backTracking(digits, numStrings, 0);

        return res;

    }

    private void backTracking(String digits, String[] numStrings, int num) {
        if (num == digits.length()) {
            res.add(sb.toString());
            return;
        }

        //先获取对应字符串
        String string = numStrings[digits.charAt(num) - '0'];
        for (int i = 0; i < string.length(); i++) {
            sb.append(string.charAt(i));
            backTracking(digits, numStrings, num + 1);
            //回溯
            sb.deleteCharAt(sb.length() - 1);
        }


    }
}
